<?php

class Admin_HomeController extends Zend_Controller_Action
{

    public function init()
    {
        $options = array(
                'layout' => 'layout',
                'layoutPath' => LAYOUT_PATH . "/admincp"
        );
        Zend_Layout::startMvc($options);
    }

    public function indexAction()
    {
        // action body
    }

    public function osAction()
    {
        $this->view->headScript()->appendFile(TEMPLATE_URL.'/min/g=js-ad-app-os');
        $this->view->headTitle('Hệ đều hành - '._page_title);
        $this->view->page_header = "Hệ đều hành";
        $mOs = new Application_Model_Os();
        
        if($this->_request->isPost()){
            $action = trim(strip_tags($_GET['action']));
            if($action == "add"){
                $result = array();
                $mOs->os_name = trim(strip_tags($_POST['os_name']));
                $mOs->os_status = trim(strip_tags($_POST['os_status']));
                if($mOs->insertOs()){
                    $result['status']=true;
                    $result['data'] = $mOs->getAll();
                }else{
                    $result['status']=false;
                }
            }
            if($action == "delete"){
                $mOs->deleteID(trim(strip_tags($_POST['os_id'])));                
            }
        }
        $this->view->data = $mOs->getAll();
    }

    public function osversionAction()
    {
        $this->view->headScript()->appendFile(TEMPLATE_URL.'/min/g=js-ad-app-osv');
        $this->view->headTitle('Phiên bản hệ đều hành - '._page_title);
        $this->view->page_header = "Phiên bản hệ đều hành";
        $mOs = new Application_Model_Os();
        $mOsv = new Application_Model_Osversion();
        if($this->_request->isPost()){
        	$action = trim(strip_tags($_GET['action']));
        	if($action == "add"){
        	    $mOsv = new Application_Model_Osversion();
        		$result = array();
        		$mOsv->os_id = trim(strip_tags($_POST['os_id']));
        		$mOsv->osv_name = trim(strip_tags($_POST['osv_name']));
        		$mOsv->osv_status = trim(strip_tags($_POST['osv_status']));
        		if($mOsv->insertOsv()){
        			$result['status']=true;
        			$result['data'] = $mOsv->getAll();
        		}else{
        			$result['status']=false;
        		}
        	}
        	if($action == "delete"){
        		$mOsv->deleteID(trim(strip_tags($_POST['osv_id'])));
        	}
        	if($action=='edit'){
        	    $mOsv = new Application_Model_Osversion();
        	    $mOsv->osv_id = trim(strip_tags($_POST['osv_id_edit']));
        	    $mOsv->os_id = trim(strip_tags($_POST['os_id_edit']));
        	    $mOsv->osv_name = trim(strip_tags($_POST['osv_name_edit']));
        	    $mOsv->osv_status = trim(strip_tags($_POST['osv_status_edit']));
        	    
        	    $mOsv->updateOsv();
        	}
        }
        $this->view->os = $mOs->getAll();
        $this->view->data = $mOsv->getAll();
    }

    public function compatibleAction()
    {
        $this->view->headScript()->appendFile(TEMPLATE_URL.'/min/g=js-ad-app-compatible');
        $this->view->headTitle('Các dòng thiết bị - '._page_title);
        $this->view->page_header = "Các dòng thiết bị";
        $mOs = new Application_Model_Os();
        $mCom = new Application_Model_Compatible();
        if($this->_request->isPost()){
        	$action = trim(strip_tags($_GET['action']));
        	if($action == "add"){
        		$mCom = new Application_Model_Compatible();
        		$result = array();
        		$mCom->os_id = trim(strip_tags($_POST['os_id']));
        		$mCom->cp_name = trim(strip_tags($_POST['cp_name']));
        		$mCom->cp_status = trim(strip_tags($_POST['cp_status']));
        		if($mCom->insertcp()){
        			$result['status']=true;
        			$result['data'] = $mCom->getAll();
        		}else{
        			$result['status']=false;
        		}
        	}
        	if($action == "delete"){
        		$mCom->deleteID(trim(strip_tags($_POST['cp_id'])));
        	}
        	if($action=='edit'){        	    
        		$mCom = new Application_Model_Compatible();
        		$mCom->cp_id = trim(strip_tags($_POST['cp_id_edit']));
        		$mCom->os_id = trim(strip_tags($_POST['os_id_edit']));
        		$mCom->cp_name = trim(strip_tags($_POST['cp_name_edit']));
        		$mCom->cp_status = trim(strip_tags($_POST['cp_status_edit']));
        
        		$mCom->updatecp();
        	}
        }
        $this->view->os = $mOs->getAll();
        $this->view->data = $mCom->getAll();
    }

    public function categoryAction()
    {
        $this->view->headScript()->appendFile(TEMPLATE_URL.'/min/g=js-ad-app-cat');
        $this->view->headTitle('Danh mục ứng dụng - '._page_title);
        $this->view->page_header = "Danh mục ứng dụng";
        $mCat = new Application_Model_Categories();
        $func = new Application_Model_Functions();
        if($this->_request->isPost()){
        	$action = trim(strip_tags($_GET['action']));
        	if($action == "add"){
        		$mCat = new Application_Model_Categories();
        		$result = array();
        		
        		$mCat->cat_name = trim(strip_tags($_POST['cat_name']));
        		$mCat->cat_slug = $func->ChangeToSlug(trim(strip_tags($_POST['cat_name'])));
        		$mCat->cat_status = trim(strip_tags($_POST['cat_status']));
        		if($mCat->insertCat()){
        			$result['status']=true;
        			$result['data'] = $mCat->getAll();
        		}else{
        			$result['status']=false;
        		}
        	}
        	if($action == "delete"){
        		$mCat->deleteID(trim(strip_tags($_POST['cat_id'])));
        	}
        	if($action=='edit'){
        		$mCat = new Application_Model_Categories();
        		$mCat->cat_id = trim(strip_tags($_POST['cat_id_edit']));
        		$mCat->cat_name = trim(strip_tags($_POST['cat_name_edit']));
        		$mCat->cat_status = trim(strip_tags($_POST['cat_status_edit']));
        
        		$mCat->updatecat();
        	}
        }
        $this->view->data = $mCat->getAll();
    }


}










